import { defineStore } from "pinia";
import { Ref, ref } from "vue";
export const useStore = defineStore("user", () => {
  //令牌
  const token: Ref<string> = ref("");
  //用户id
  const uid: Ref<string> = ref("");
  // 用户名
  const userinfo: Ref<any> = ref({});

  interface loginInfoStorageInterface {
    token: string,
    uid: string,
    userinfo: any,
  }
   // 登录
   const login = (loginInfo: loginInfoStorageInterface) => {
    token.value = loginInfo.token || '';
    uid.value = loginInfo.uid || '';
    userinfo.value = loginInfo.userinfo || {};
  }
  const logout = () => {
    token.value = '';
    uid.value = '';
    userinfo.value = {};
  }
  return {
    token,
    uid,
    userinfo,
    login,
    logout,
  }

},
{
  persist: {
    enabled: true,
    strategies: [{
      key: process.env.VUE_APP_ENV + "user",
      storage: localStorage,
    }]
  }
} as any);